<template>
  <div
    class="sliderMenu"
    :class="menuClass"
    @mouseover="isHover = true"
    @mouseleave="isHover = false"
  >
    <div
      class="menu_item"
      v-for="(item, index) in menus"
      :key="index"
      @click="clickMenu(item)"
    >
      <div class="menu_item_icon" :title="item.label">
        <!-- <el-tooltip effect="dark" :content="item.label" placement="bottom"> -->
          <i v-if="item.icon.indexOf('http') < 0" :class="item.icon||'el-icon-menu'"></i>
          <img v-else :src="item.icon" alt="" />
        <!-- </el-tooltip> -->
      </div>
      <div class="menu_item_label">{{ item.label }}</div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from "vue";
import { useRouter } from "vue-router";
// import { menus } from "../../menu";
import { MenuItem } from "../../types/type";
export default defineComponent({
  name: "JimuSliderMenu",
  props: {
    menus: Array
  },
  setup(props) {
    const isHover = ref<boolean>(false);
    const menuClass = ref("");
    const router = useRouter();

    // let menuTimer: NodeJS.Timeout | null = null;
    let menuTimer: any = null;

    const clickMenu = (item: any) => {
      if (item.linkType == "route") {
        router.push(item.router);
      }
    };

    watch(isHover, (value: boolean) => {
      //直接监听
      const clearTimeoutFnc = () => {
        if (menuTimer) {
          clearTimeout(menuTimer);
        }
      };
      if (value) {
        menuTimer = setTimeout(() => {
          menuClass.value = "showMenuMove";
          clearTimeoutFnc();
        }, 500);
      } else {
        clearTimeoutFnc();
        menuClass.value = "hiddenMenuMove";
      }
    });
    return {
      // menus,
      isHover,
      menuClass,
      clickMenu,
    };
  },
});
</script>
<style lang="scss" scoped>
.sliderMenu {

  box-sizing: border-box;
  width: 50px;
  display: flex;
  flex-direction: column;
  position: fixed;
  z-index: 810;
  top: 50px;
  left: 0;
  border-right: 1px solid #e6e6e6;
  bottom: 0;
  font-size: 12px;
  background: #fff;
  overflow-x: hidden;


  &.showMenuMove {
    animation: showMenu 0.2s forwards;
  }
  &.hiddenMenuMove {
    animation: hiddenMenu 0.2s forwards;
  }
  .menu_item {
    display: flex;
    justify-content: space-between;
    width: 250px;
    cursor: pointer;
    &:hover {
      background: #f2f5fc;
      color: #526ecc;
    }
    .menu_item_icon {
      width: 50px;
      height: 40px;
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .menu_item_label {
      flex: 1;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      padding-left: 8px;
    }
  }
}
</style>

<style>
@keyframes showMenu {
  from {
    width: 50px;
  }
  to {
    width: 250px;
  }
}
@keyframes hiddenMenu {
  from {
    width: 250px;
  }
  to {
    width: 50px;
  }
}
</style>
